#include <im.h>
#include <im_binfile.h>
#include <stdlib.h>
#include <string.h>

#ifdef WIN32
#define EXPORT(T) __declspec(dllexport) T
#elif defined LIN26
#define EXPORT(T) T
#endif

//for now, we only export a few functions to allow streaming of images

EXPORT(int) BinFileSetCurrentModule(int mode) {return imBinFileSetCurrentModule(mode);}

EXPORT(imBinMemoryFileName*) CreateMemFileName(void* buffer,int buflen) {
    imBinMemoryFileName* res;

    res=malloc(sizeof(imBinMemoryFileName));

    if(res==NULL)
        return NULL;

    //we have to allocate buffer since we cant guarantee .net garabage collector dont move memory
    //and we sure dont know that the buffer is pinned
    res->buffer=malloc(buflen);
    memcpy(res->buffer,buffer,buflen);


    res->size=buflen;
    res->reallocate=0;


    return res;

}

EXPORT(void) DestroyMemeFileName(imBinMemoryFileName* fn) {
    if(fn!=NULL) {
        if(fn->buffer!=NULL)
            free(fn->buffer);
        free(fn);
    }
}
